package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.os.service.FoodServiceS;
import com.os.serviceimpl.FoodServiceImplS;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 删除菜谱controller
 * @author 小H下午2:57:47
 *
 */
public class DelFoodControllerS extends HttpServlet{
	FoodServiceS fs = new FoodServiceImplS();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("utf8");
		boolean flag = false;
		String a =  req.getParameter("data");
		JSONArray s = JSONArray.fromObject(a);
		for (int i = 0; i < s.size(); i++) {
			JSONObject job = new JSONObject();
			JSONObject jj = job.fromObject(s.get(i));
			flag = fs.delFoodsS(Integer.parseInt(jj.getString("fid")));
		}
		PrintWriter pw = resp.getWriter();
		JSONObject q = new JSONObject();
		q.put("flag", flag);
		pw.write(q.toString());
		pw.flush();
		pw.close();

	}
}
